//package com.ego.sms.listener;
//
//import com.aliyun.dysmsapi20170525.Client;
//import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
//import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
//import com.aliyun.teaopenapi.models.Config;
//import com.ego.sms.properties.SmsProperties;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.stereotype.Component;
//
//@Slf4j
//@Component
//@EnableConfigurationProperties(SmsListener.class)
//public class SmsListener {
//
//    @Autowired
//    private SmsProperties smsProperties;
//
//    public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
//        Config config = new Config()
//                // 您的AccessKey ID
//                .setAccessKeyId(accessKeyId)
//                // 您的AccessKey Secret
//                .setAccessKeySecret(accessKeySecret);
//        // 访问的域名
//        config.endpoint = "dysmsapi.aliyuncs.com";
//        return new Client(config);
//    }
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(value = "ego.sms.queue", durable = "true"),
//            exchange = @Exchange(value = "ego.sms.exchange",
//                    ignoreDeclarationExceptions = "true"),
//            key = {"sms.verify.code"}))
//    public void sendSms(String data){
//        //解析数据
//        String[] split = data.split("&&&");
//        String phone = split[0];
//        String code = split[1];
//
//        //调用阿里云短信平台发送短信
//
//        Client client = null;
//
//
//        try {
//            client = SmsListener.createClient(smsProperties.getAccessKeyID(), smsProperties.getAccessKeySecret());
//            SendSmsRequest sendSmsRequest = new SendSmsRequest()
//                    .setPhoneNumbers(phone)
//                    .setSignName(smsProperties.getTempalteSign())
//                    .setTemplateCode(smsProperties.getTempalteCode())
//                    .setTemplateParam("{\"code\":\""+code+"\"}");
//            // 复制代码运行请自行打印 API 的返回值
//            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
//            log.debug("短信发送结果:{}"+sendSmsResponse);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }
//}
